package view;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class View {
	
	int a,b,c,d,e,f,g,h;
	
	public View()
	{
		a = 100;
		b = 100;
		c = 300;
		d = 100;
		e = 300;
		f = 300;
		g = 100;
		h = 300;
			
	}
	
	public void start() {
		try {
			Display.setDisplayMode(new DisplayMode(1200,750));
			Display.setTitle("Worlds");
			Display.create();
		} catch (LWJGLException e) {
			e.printStackTrace();
			System.exit(0);
		}
		
		// init OpenGL here
		GL11.glMatrixMode(GL11.GL_PROJECTION);		
		GL11.glLoadIdentity();
		GL11.glOrtho(0, 800, 0, 600, 1, -1);	
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		
		while (!Display.isCloseRequested()) {		
			  // Clear the screen and depth buffer
		    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);	
			
		    // set the color of the quad (R,G,B,A)
		    GL11.glColor3f(0.5f,0.5f,1.0f);
		    	
		    // draw quad
		    GL11.glBegin(GL11.GL_QUADS);
		    //vertex
		    GL11.glVertex2f(a,b);
			GL11.glVertex2f(c,d);
			GL11.glVertex2f(e,f);
			GL11.glVertex2f(g,h);
		    GL11.glEnd();
			checkInput();
			Display.update();
		}
		Display.destroy();
	}
	
	public void checkInput(){
		while(Keyboard.next()){
			if(Keyboard.getEventKeyState()){
				if(Keyboard.getEventKey() == (Keyboard.KEY_DOWN)){
					System.out.println("down key pressed");
					    b-=100;
						d-=100;
						f-=100;
						h-=100;
						Display.update();
						
				}
				if(Keyboard.getEventKey() == (Keyboard.KEY_UP)){
					System.out.println("up key pressed");
					//tell controller to tell model something
					b+=100;
					d+=100;
					f+=100;
					h+=100;
				}
				if(Keyboard.getEventKey() == (Keyboard.KEY_LEFT)){
					System.out.println("left key pressed");
					//tell controller to tell model something
					a-=100;
					c-=100;
					e-=100;
					g-=100;
				}
				if(Keyboard.getEventKey() == (Keyboard.KEY_RIGHT)){
					System.out.println("right key pressed");
					//tell controller to tell model something
					a+=100;
					c+=100;
					e+=100;
					g+=100;
				}
			}else{			
				if(Keyboard.getEventKey() == (Keyboard.KEY_DOWN)){
					System.out.println("down key released");
					//tell controller to tell model something
				}
				if(Keyboard.getEventKey() == (Keyboard.KEY_UP)){
					System.out.println("up key released");
					//tell controller to tell model something
				}
				if(Keyboard.getEventKey() == (Keyboard.KEY_LEFT)){
					System.out.println("left key released");
					//tell controller to tell model something
				}
				if(Keyboard.getEventKey() == (Keyboard.KEY_RIGHT)){
					System.out.println("right key released");
					//tell controller to tell model something
				}
			}
		}
		}
	
	
	public static void main(String[] argv) {
		View view = new View();
		view.start();
	}
}